package com.factory.iamp.dao;

import com.factory.iamp.pojo.QuestionManager;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface QuestionMapper {

    @Select("select count(qid) from question_manager where ${QueryStr}")
    int QueryCount(@Param("QueryStr") String QueryStr);

    @Select("select * from question_manager where ${QueryStr} order by process_at desc limit #{offset}, #{limit}")
    @Results({
            @Result(property = "recorder", column = "recorder"),
            @Result(
                    property = "recorder_info", column = "recorder",
                    one = @One(select = "com.factory.iamp.dao.UserMapper.findById")
            )
    })
    List<QuestionManager> QueryListPaged(
            @Param("offset") int offset, @Param("limit") int limit, @Param("QueryStr") String QueryStr
    );

    @Insert({
            "insert into question_manager(department, product_type, process_type, product_name, question_summary, ",
            "question_description, pic, process_method, recorder) ",
            "values (#{department}, #{product_type}, #{process_type}, #{name}, #{summary}, #{description}, ",
            "#{file}, #{method}, #{recorder})"
    })
    void addQuestionRecord(
            @Param("name") String name, @Param("department") String department,
            @Param("product_type") String product_type, @Param("process_type") String process_type,
            @Param("summary") String summary, @Param("description") String description,
            @Param("method") String method, @Param("recorder") String recorder, @Param("file") String file
    );

    @Update({
            "update question_manager set department = #{department}, product_type = #{product_type}, ",
            "process_type = #{process_type}, product_name = #{name}, question_summary = #{summary}, ",
            "question_description = #{description}, pic = #{file}, process_method = #{method}, recorder = #{recorder} ",
            "where qid = #{qid}"
    })
    void alterQuestionRecord(
            @Param("qid") int qid, @Param("name") String name, @Param("department") String department,
            @Param("product_type") String product_type, @Param("process_type") String process_type,
            @Param("summary") String summary, @Param("description") String description,
            @Param("method") String method, @Param("recorder") String recorder, @Param("file") String file
    );

    @Delete("delete from question_manager where qid = #{qid}")
    void deleteQuestionRecord(@Param("qid") int qid);
}
